<?php 
//create by fu
namespace app\api\model;

use app\api\model\BaseModel;

/**
 * 
 */
class Theme extends BaseModel
{
	//隐藏字段
	protected $hidden = ['delete_time','update_time','topic_img_id','head_img_id'];
	
	//关联模型
	public function topicImg()
	{
		return $this->belongsTo('Image','topic_img_id','id');
	}
	public function headImg()
	{
		return $this->belongsTo('Image','head_img_id','id');
	}

	//关联多对多
	//belongsToMany(本模型对面的表,中间表,中间表的对面表外键,中间表的本模型外键);
	public function products()
	{
		return $this->belongsToMany('Product','theme_product','product_id','theme_id');
	}

	//根据id获取本专题图片
    static function getThemeWithProducts($id)
    {
    	$theme = self::with('products,headImg,topicImg')->find($id);

    	return $theme;
    }

}




 ?>